#include "PrecompiledHeader_Reborn.h"
#include "Atmosphere.h"

/*--------------------------------------------------------------------------*/

Atmosphere::Atmosphere(CelestialPlanet* owner)
{
	this->m_owner = owner;
	this->m_inner = g_Material->GetMaterial("mat_atmosphere");
	this->m_outer = g_Material->GetMaterial("mat_atmosphere");
}

/*--------------------------------------------------------------------------*/

Atmosphere::~Atmosphere()
{
}

/*--------------------------------------------------------------------------*/

void Atmosphere::Draw(EAtmosphere::Enum type, const glm::vec3& cam, const glm::vec3& center, const glm::vec3& sun, float camh, float innerr, float outerr)
{

	switch (type)
	{
	case EAtmosphere::Inner:
	{
		g_Material->BindMaterial(this->m_inner, EMaterialTechnique::Default);

		ROpenGL::SetUniformBufferValue(g_Renderer->GetUniformBuffer(EUbo::Commons), EUboCommons::Var_0, (void*) &cam);
		ROpenGL::SetUniformBufferValue(g_Renderer->GetUniformBuffer(EUbo::Commons), EUboCommons::Var_1, (void*) &center);
		ROpenGL::SetUniformBufferValue(g_Renderer->GetUniformBuffer(EUbo::Commons), EUboCommons::Var_2, (void*) &sun);

		glm::vec3 d = glm::vec3(camh, innerr, outerr);
		ROpenGL::SetUniformBufferValue(g_Renderer->GetUniformBuffer(EUbo::Commons), EUboCommons::Var_3, (void*) &d);

		ROpenGL::BindVertexArray(ROpenGL::GetLargeSphereVao());
		ROpenGL::DrawVertexArray(0);
		break;
	}

	case EAtmosphere::Outer:
	{
		g_Material->BindMaterial(this->m_outer, EMaterialTechnique::Default);

// 		vec3 env_camPos       = Var_0.xyz;
// 		vec3 env_centerPos    = Var_1.xyz;
// 		vec3 env_sunPos       = Var_2.xyz;
//
// 		float fCameraHeight   = Var_3.x;
// 		float fInnerRadius    = Var_3.y;
// 		float fOuterRadius    = Var_3.z;

		ROpenGL::SetUniformBufferValue(g_Renderer->GetUniformBuffer(EUbo::Commons), EUboCommons::Var_0, (void*) &cam);
		ROpenGL::SetUniformBufferValue(g_Renderer->GetUniformBuffer(EUbo::Commons), EUboCommons::Var_1, (void*) &center);
		ROpenGL::SetUniformBufferValue(g_Renderer->GetUniformBuffer(EUbo::Commons), EUboCommons::Var_2, (void*) &sun);

		glm::vec3 d = glm::vec3(camh, innerr, outerr);
		ROpenGL::SetUniformBufferValue(g_Renderer->GetUniformBuffer(EUbo::Commons), EUboCommons::Var_3, (void*) &d);

		ROpenGL::BindVertexArray(ROpenGL::GetLargeSphereVao());
		ROpenGL::DrawVertexArray(0);
		break;
	}

	default:
	{
		AssertLogC(true, "Unknown EAtmosphere");
	}
	}
}

/*--------------------------------------------------------------------------*/